package net.janeluo.rs.module;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import net.janeluo.rs.entity.RS_Menus;
import net.janeluo.rs.entity.RS_Shops;
import net.janeluo.rs.entity.RS_SymNotice;
import net.janeluo.rs.entity.RS_User;
import net.janeluo.rs.service.UserIndexService;

import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

/**
 * 用户首页模块
 * 
 * @author DLK)JaneLuo
 * @version 1.0.0
 */
@IocBean
@At("/")
public class UserIndexModule {

    @Inject
    private UserIndexService userIndexService;

    /**
     * 初始化显示用户首页
     * 
     * @return
     */
    @At("InitUserIndex")
    @Ok("jsp:views.UserIndex")
    public Map<RS_Shops, List<RS_Menus>> initUserIndex(HttpServletRequest req) {
        req.getSession().setAttribute("menuName", "InitUserIndex");
        List<RS_SymNotice> noticeLst = userIndexService.searchNoticeLst();
        req.setAttribute("notices", noticeLst);
        return userIndexService.init();
    }

    /**
     * 用户注册
     */
    @At("UserRegist")
    @Ok("->:/InitUserIndex.nut")
    public void addUser(HttpServletRequest req, @Param("..") RS_User user){
        
        RS_User user2 = userIndexService.insertUser(user);
        
        req.getSession().setAttribute("user", user2);
        
    }

    @At("UserAddOrder")
    @Ok("->:/InitUserIndex.nut")
    public void userAddOrder(HttpServletRequest req, @Param("midarr") Integer[] midarr, @Param("mnamearr") String[] mnamearr,
            @Param("nums") String[] nums, @Param("totalPrice") String totalPrice) {
        RS_User user = (RS_User) req.getSession().getAttribute("user");
        userIndexService.saveUserOrder(user, midarr, mnamearr, nums, totalPrice);
    }
}
